import plotly.express as px

from die import Die

die = Die()
die2 = Die()

# 生成随机数
results = []
for roll_num in range(1000):
    result = die.roll()+die2.roll()
    results.append(result)

# 分析每个数字出现的次数
frequencies=[]
poss_results = range(1,die.num_sides+die2.num_sides+1)
for value in poss_results:
    frequency = results.count(value)
    frequencies.append(frequency)
print(frequencies)

title = '掷骰子统计'
labels = {'x':'result', 'y':'count'}
fig = px.bar(x=poss_results, y=frequencies, title=title, labels=labels)
fig.update_layout(xaxis_dtick=1)
fig.show()

# 生成html文件
fig.write_html('test_plotly.html')

